<template>
  <div class="dashboard">
    <van-row gutter="20">
      <!-- 操作系统信息 -->
      <van-col span="24">
        <van-card class="box-card">
          <template #title>
            <div class="card-header">
              <span>Operating System</span>
            </div>
          </template>
          <template #desc>
            <div class="text item">
              {{ systemInfo.operatingSystem }}
            </div>
          </template>
        </van-card>
      </van-col>

      <!-- 处理器信息 -->
      <van-col span="24">
        <van-card class="box-card">
          <template #title>
            <div class="card-header">
              <span>Processor</span>
            </div>
          </template>
          <template #desc>
            <div class="text item">
              <div>{{ systemInfo.processor.split('\n')[0] }}</div>
              <div>{{ systemInfo.processor.split('\n')[1] }}</div>
              <div>{{ systemInfo.processor.split('\n')[2] }}</div>
              <div>{{ systemInfo.processor.split('\n')[3] }}</div>
            </div>
          </template>
        </van-card>
      </van-col>

      <!-- 内存信息 -->
      <van-col span="24">
        <van-card class="box-card">
          <template #title>
            <div class="card-header">
              <span>Memory</span>
            </div>
          </template>
          <template #desc>
            <div class="text item">
              {{ systemInfo.memory }}
            </div>
          </template>
        </van-card>
      </van-col>
    </van-row>
  </div>
</template>

<script>
import { ref, onMounted } from 'vue';
import request from '@/utils/request';
import { Row as VanRow, Col as VanCol, Card as VanCard } from 'vant';

export default {
  components: {
    VanRow,
    VanCol,
    VanCard
  },
  setup() {
    const systemInfo = ref({
      operatingSystem: '',
      processor: '',
      memory: ''
    });

    const fetchSystemInfo = async () => {
      try {
        const response = await request.get('/api/systemInfo');

        if (response.status === 'success') {
          systemInfo.value = response.data;
        }
      } catch (error) {
        console.error('Error fetching system info:', error);
      }
    };

    onMounted(() => {
      fetchSystemInfo();
    });

    return {
      systemInfo
    };
  }
};
</script>

<style scoped>
.dashboard {
  width: 100%;
}

.box-card {
  width: 100%;
  margin: 20px 0;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}
</style>